package com.study.thread;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class SyncObjectClass {

    Logger logger = LoggerFactory.getLogger(SyncObjectClass.class);

    Integer integer;

    public Integer getInteger() {
        return integer;
    }

    public void setInteger(Integer integer) {
        this.integer = integer;
    }

    public SyncObjectClass() {
    }

    public SyncObjectClass(Integer integer) {
        this.integer = integer;
    }

    /**
     * @description 同步代码块传参变量对象 （锁住的是变量对象）
     * @author hw
     * @date 2021/12/30 14:22:02
     */
    public synchronized void test1(){
        synchronized(integer){
            try {
                logger.info(Thread.currentThread().getName() + "test1 进入了同步块 " + integer);
                Thread.sleep(5000);
                logger.info(Thread.currentThread().getName() + "test1 休眠结束 " + integer);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
